<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>设置</title>
    <link href="../../css/common.css" rel="stylesheet"/>
    <link href="../../css/user/setting.css" rel="stylesheet"/>
    <link href="../../css/mui.min.css" rel="stylesheet"/>
    <script src="../../js/vue.min.js"></script>
    <script src="../../js/mui.min.js"></script>
    <script src="../../js/fastclick.js"></script>
    <script src="../../js/api.js"></script>
    <script src="../../js/common.js"></script>
    <script src="../../js/vue-common.js"></script>
    <script src="../../js/checkversion.js"></script>
</head>
<body>
<div id="app">
    <div class="header-nav">
        <span>设置</span>
        <div class="icon"><img src="../../img/common/btn_back.png" alt=""></div>
    </div>

    <div class="container setting">
        <div class="st-list-box">

            <div class="st-item" @click="goPassword">
                <div class="left">修改密码</div>
                <div class="right"><img src="../../img/common/btn_more.png" alt=""></div>
            </div>

            <div class="st-item">
                <div class="left">关于修乐巴</div>
                <div class="right">{{version}} <span v-show="updateVersion" class="dot"></span><img src="../../img/common/btn_more.png" alt=""></div>
            </div>

            <div class="st-item">
                <div class="left">检查更新</div>
                <div class="right" @click="checkVersion"><img src="../../img/common/btn_more.png" alt=""></div>
            </div>

            <div class="st-item" v-if="useManual">
                <div class="left">使用手册</div>
                <div class="right" @click="goAppUseInfo"><img src="../../img/common/btn_more.png" alt=""></div>
            </div>

        </div>
    </div>

    <xlb-modal v-model="logoutMod" >
        <div class="dialog-content" slot="content">确定退出登录？</div>
        <div slot="footer-left">取消</div>
        <div @click="doLogout"  slot="footer-right">确定</div>
    </xlb-modal>

    <div @click="logout" class="xl-btn normal logout">退出登录</div>
</div>
<script>
    var vm = new Vue({
        el: '#app',
        mounted:function(){
            var permision = getUserPermission();
            this.useManual =permision? permision['useManual']:false;
        },
        data: {
            title: '首页',
            updateMod:false,
            serverVersion:'',
            updateProgress:0,
            updateProgressMod:false,
            logoutMod:false,
            taskObj:'',
            version:LOCAL_APP_VERSION,
            updateVersion:false,
            useManual: false // 是否显示用户手册
        },
        methods: {
            goPassword: function () {
                redirect('pages/user/doUpdatePassword.html');
            },
            logout:function(){
                this.logoutMod = true;
            },
            doLogout:function(){
                Resource.post(USER_LOG_OUT_API, {}, function (res) {
                    delUserToken();
                    // toLogoutPage();
                    redirect('pages/login/login.html')
                    vm.logoutMod = false;
                },function () {
                    redirect('pages/login/login.html')
                    vm.logoutMod = false;
                })
            },
            checkMod:function(){
                wgtWaiting = plus.nativeUI.showWaiting("检查更新中。。。");
                Resource.get(CHECK_VERSION_URL, {}, function (res) {
                    wgtWaiting.close();
                    var server_version = res.version;
                    if (!isUpdate(LOCAL_APP_VERSION, server_version)) {
                        plus.nativeUI.closeWaiting();
                        mui.alert("当前已经是最新版本！");
                        return;
                    }
                    vm.updateMod = true;
                    vm.serverVersion = server_version;
                }, function (error) {
                    plus.nativeUI.close();
                })

            },
            // 检查app版本
            checkVersion: function () {
                //跳转app
                plus.runtime.openURL('https://itunes.apple.com/us/app/%E4%BF%AE%E4%B9%90%E5%B7%B4%E6%8A%A5%E4%BF%AE%E7%AB%AF/id1397300308?l=zh&ls=1&mt=8');

            },
            // 校验最新办版本
            getNewVersion: function () {
                Resource.get(CHECK_VERSION_URL, {}, function (res) {
                    var server_version = res.version;
                    if (isUpdate(LOCAL_APP_VERSION, server_version)) {
                        vm.updateVersion = true;
                    } else {
                        vm.updateVersion = false;
                    }
                })
            },
            // 跳转App使用手册
            goAppUseInfo(){
                plus.runtime.openURL("http://new.xiuleba.com.cn/doc/jh_pd");
            }
        }
    });

    //监听初始化
    document.addEventListener('changeTab', function (data) {
        vm.getNewVersion();
    })
    mui.plusReady(function () {
        vm.getNewVersion();
    });

</script>
</body>
</html>
